import matplotlib.pyplot as plt
import numpy as np

# 指定中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']

# 数据标签
labels = ['焦虑', '抑郁', '自尊', '社交能力', '情绪调节', '应对能力']
values = [4, 3, 5, 2, 4, 3]

# 数值个数
num_vars = len(labels)

# 计算角度
angles = np.linspace(0, 2 * np.pi, num_vars, endpoint=False).tolist()

# 闭合图形
values += values[:1]
angles += angles[:1]

fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))

# 填充颜色
ax.fill(angles, values, color='blue', alpha=0.25)
# 绘制轮廓线
ax.plot(angles, values, color='blue', linewidth=2)

# 设置标签
ax.set_yticklabels([])
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels)

# 添加标题
plt.title('心理健康分析雷达图', size=20, color='blue', y=1.1)

# 显示分数
for i in range(num_vars):
    angle_rad = angles[i]
    angle_deg = np.degrees(angle_rad)
    ax.text(angle_rad, values[i] + 0.5, str(values[i]), color='blue', size=12, ha='center', va='center', rotation=angle_deg)

plt.show()
